#include<pthread.h>
#include<unistd.h>
#include<stdio.h>
#include<math.h>
#define N 100000
#define CPU_N 4
#define CHILD_N (N/CPU_N)
struct param
{
    float part_sum;
    int start;
    int end;
};

void *compute(void *arg)
{
    struct param *param;
    param=(struct param *)arg;
    float sum=0;
    int sign=pow(-1,param->start);
    for(int i=param->start+1;i<=param->end;i++)
    {
        sum+=sign*1/(2*(float)i-1);
        sign=-sign;
    }
    param->part_sum=sum;
    return param;
}

int main()
{
    pthread_t worker[CPU_N];
    struct param params[CPU_N];
    int i;
    for(int i=0;i<CPU_N;i++)
    {
        struct param *param;
        param=&params[i];
        param->start=i*CHILD_N;
        param->end=(i+1)*CHILD_N;
        pthread_create(&worker[i],NULL,compute,param);
    }
    float sum=0;
    for(int i=0;i<CPU_N;i++)
    {
        struct param *param;
        pthread_join(worker[i],(void**)&param);
        sum+=param->part_sum;
    }
    printf("%f\n",sum*4);
    return 0;
}

